home *** CD-ROM | disk | FTP | other *** search
/ How Many Bugs in a Box / How Many Bugs in a Box.cdr / bugs / act7 / 00027_bughive.ls < prev    next >
Encoding:
Text File  |  1995-03-28  |  6.3 KB  |  260 lines

  1. property bx, by, binx, biny, mode, schan, findex, cnum, destx, desty, btype, animstep, direction, ancestor
  2.  
  3. on birth me, snum, bugtype
  4.   global jumpindex
  5.   set schan to snum
  6.   set btype to bugtype
  7.   set cnum to the castNum of sprite schan
  8.   set bx to the locH of sprite schan
  9.   set by to the locV of sprite schan
  10.   set animstep to 1
  11.   set direction to 1
  12.   set destx to random(290) + 200
  13.   set desty to random(280) + 100
  14.   puppetSprite(snum, 1)
  15.   if btype < 7 then
  16.     set mode to #flying
  17.   else
  18.     if btype < 11 then
  19.       set mode to #crawling
  20.       set direction to directix(bx, destx, bx, bx) / 4
  21.     else
  22.       set mode to #wander
  23.       set binx to 3 * sgn(destx - bx)
  24.       set biny to 3 * sgn(desty - by)
  25.       set direction to directix(bx, by, destx, desty)
  26.     end if
  27.   end if
  28.   return me
  29. end
  30.  
  31. on settask me, newtask
  32.   set mode to newtask
  33. end
  34.  
  35. on animate me
  36.   global blevel, semisin
  37.   set animstep to animstep + 1
  38.   if mode = #caught then
  39.     set bx to the mouseH
  40.     set by to the mouseV
  41.     if not (the mouseDown) then
  42.       set mode to #return
  43.     end if
  44.   end if
  45.   if mode = #wander then
  46.     if animstep > 1 then
  47.       set animstep to 0
  48.     end if
  49.     set the castNum of sprite schan to cnum + (direction * 2) + animstep
  50.     set bx to bx + binx
  51.     set by to by + biny
  52.     if random(30) = 1 then
  53.       set mode to #wander2
  54.     end if
  55.     if (bx < 150) or (bx > 700) or (by < -50) or (by > 530) then
  56.       set mode to #frighten
  57.     end if
  58.     set the castNum of sprite schan to cnum + (direction * 2) + animstep
  59.     if random(10) = 1 then
  60.       set direction to direction + random(3) - 2
  61.       if direction > 7 then
  62.         set direction to 0
  63.       end if
  64.       if direction < 0 then
  65.         set direction to 7
  66.       end if
  67.       set binx to getPropAt(semisin, direction + 1)
  68.       set biny to getAt(semisin, direction + 1)
  69.     end if
  70.     if bx < 200 then
  71.       set direction to random(5) + 3
  72.       if direction > 7 then
  73.         set direction to 1
  74.       end if
  75.       set binx to getPropAt(semisin, direction + 1)
  76.       set biny to getAt(semisin, direction + 1)
  77.     end if
  78.   end if
  79.   if mode = #wander2 then
  80.     if animstep > 1 then
  81.       set animstep to 0
  82.     end if
  83.     set direction to direction + 1
  84.     if direction > 7 then
  85.       set direction to 0
  86.     end if
  87.     set the castNum of sprite schan to cnum + (direction * 2) + animstep
  88.     if random(10) = 1 then
  89.       set binx to getPropAt(semisin, direction + 1)
  90.       set biny to getAt(semisin, direction + 1)
  91.       set mode to #wander
  92.     end if
  93.     if bx < 200 then
  94.       set direction to random(5) + 3
  95.       if direction > 7 then
  96.         set direction to 1
  97.       end if
  98.       set binx to getPropAt(semisin, direction + 1)
  99.       set biny to getAt(semisin, direction + 1)
  100.     end if
  101.   end if
  102.   if mode = #flying then
  103.     if animstep > 2 then
  104.       set animstep to 0
  105.     end if
  106.     set the castNum of sprite schan to cnum + animstep
  107.     set bx to bx + (sgn(destx - bx) * blevel)
  108.     set by to by + (sgn(desty - by) * blevel)
  109.     if (abs(destx - bx) < 7) and (abs(desty - by) < 7) then
  110.       set destx to random(290) + 200
  111.       set desty to random(280) + 100
  112.       if random(3) = 1 then
  113.         set mode to #frighten
  114.       end if
  115.     end if
  116.   end if
  117.   if mode = #runaway then
  118.     if (by < 500) and (by > 0) and (bx > 0) and (bx < 640) then
  119.       set bx to bx + binx
  120.       set by to by + biny
  121.     else
  122.       killbug(schan)
  123.       set mode to #killhim
  124.     end if
  125.   end if
  126.   if mode = #frighten then
  127.     set binx to (-1 + ((random(2) - 1) * 3)) * 16
  128.     set biny to (-1 + ((random(2) - 1) * 3)) * 16
  129.     set mode to #runaway
  130.   end if
  131.   if mode = #crawling then
  132.     if animstep > 2 then
  133.       set animstep to 0
  134.     end if
  135.     set the castNum of sprite schan to cnum + (direction * 3) + animstep
  136.     set bx to bx + (sgn(destx - bx) * 2)
  137.     if abs(destx - bx) < 7 then
  138.       set destx to 700
  139.       set direction to directix(bx, destx, bx, bx) / 4
  140.       set mode to #diecrawling
  141.     end if
  142.   end if
  143.   if mode = #diecrawling then
  144.     if animstep > 2 then
  145.       set animstep to 0
  146.     end if
  147.     set the castNum of sprite schan to cnum + (direction * 3) + animstep
  148.     set bx to bx + (sgn(destx - bx) * blevel * 2)
  149.     if abs(destx - bx) < 7 then
  150.       set mode to #killhim
  151.     end if
  152.   end if
  153.   if mode = #return then
  154.     if (bx < 0) or (bx > 640) or (by < 0) or (by > 480) then
  155.       kill(me)
  156.       killbug(schan)
  157.       addbug()
  158.       exit
  159.     end if
  160.     if btype < 7 then
  161.       set mode to #flying
  162.     else
  163.       if btype < 11 then
  164.         set mode to #falling
  165.         set biny to 1
  166.         if by < 231 then
  167.           set desty to 231
  168.         else
  169.           set desty to 476
  170.         end if
  171.         set destx to bx
  172.       else
  173.         set mode to #wander
  174.       end if
  175.     end if
  176.   end if
  177.   if mode = #falling then
  178.     if animstep > 2 then
  179.       set animstep to 0
  180.     end if
  181.     set the castNum of sprite schan to cnum + (direction * 3) + animstep
  182.     set by to by + biny
  183.     if biny < 16 then
  184.       set biny to biny * 2
  185.     end if
  186.     if by > desty then
  187.       set by to desty
  188.       set destx to random(740) - 50
  189.       set direction to directix(bx, destx, bx, bx) / 4
  190.       set mode to #crawling
  191.     end if
  192.   end if
  193.   if mode = #killhim then
  194.     set the locV of sprite schan to -200
  195.     set by to -200
  196.     kill(me)
  197.     killbug(schan)
  198.   end if
  199.   if mode = #escaping then
  200.     if animstep > 1 then
  201.       set animstep to 0
  202.     end if
  203.     set the castNum of sprite schan to cnum
  204.     set bx to bx + (sgn(destx - bx) * blevel * 2)
  205.     set by to by + (sgn(desty - by) * blevel * 2)
  206.     if by > 445 then
  207.       set by to 446
  208.       if abs(bx - destx) < 20 then
  209.         set mode to #killhim
  210.       end if
  211.     end if
  212.   end if
  213.   set the locH of sprite schan to bx
  214.   set the locV of sprite schan to by
  215. end
  216.  
  217. on setdest me, newx, newy
  218.   set destx to newx
  219.   set desty to newy
  220. end
  221.  
  222. on setbugx me, bnx
  223.   set bx to bnx
  224. end
  225.  
  226. on setbugxy me, bnx, bny
  227.   set bx to bnx
  228.   set by to bny
  229. end
  230.  
  231. on setcastnum me, settocnum
  232.   set cnum to settocnum
  233.   set the castNum of sprite schan to cnum
  234. end
  235.  
  236. on getbugtype me
  237.   return btype
  238. end
  239.  
  240. on kill me
  241.   set me to 0
  242. end
  243.  
  244. on buginfo me
  245.   put bx, by, binx, biny, destx, desty
  246.   put cnum, schan, findex
  247. end
  248.  
  249. on variance me
  250.   set temprand to random(4)
  251.   set cnum to the number of cast string("b" & temprand)
  252.   set mode to getAt([#bounce, #nothing, #going], temprand)
  253.   set binx to (random(5) - 3) * 3
  254.   set biny to (random(5) - 3) * 3
  255.   if mode = #going then
  256.     set destx to 50 + random(412)
  257.     set desty to 25 + random(334)
  258.   end if
  259. end
  260.